
package myprogramui;

import brain.MyBrain;
import controller.MyController;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.LineBuilder;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import myprogramui.comp.AnalysisPage;
import myprogramui.comp.Circle_Ani;
import myprogramui.comp.DrillPage;
import myprogramui.comp.Header;
import myprogramui.comp.LeftButton;
import myprogramui.comp.SettingPage;
import myproj.Main;

/**
 *
 * @author Administrator
 */
public class MyProgramUI extends Application {
    private Point2D anchorPt; 
    private Point2D previousLocation; 
    private MyController controller;
    private MyBrain brain;
    DropShadow dropShadow = new DropShadow();
    private BooleanProperty page1BooleanProperty=new SimpleBooleanProperty(true);
    private BooleanProperty page2BooleanProperty=new SimpleBooleanProperty(false);
    private BooleanProperty page3BooleanProperty=new SimpleBooleanProperty(false);
    private Main threeDMain=new Main();
//    private String centerCSS="-fx-background-image: url(\"CoarseGrid.png\");\n" +
//                            "    -fx-background-repeat: repeat;\n" +
//                            "    -fx-background-color:\n" +
//                            "        linear-gradient(#38424b 0%, #1f2429 20%, #191d22 100%),\n" +
//                            "        linear-gradient(#20262b, #191d22),\n" +
//                            "        radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));";
    @Override
    public void start(Stage primaryStage) {        
        try {            
            threeDMain.getJFrame().setVisible(false);
            threeDMain.mainxx(new String[]{});
            this.controller=threeDMain.getController();
            this.brain=threeDMain.getBrain();
            makeUpConstruction(primaryStage);
        } catch (InterruptedException ex) {
            Logger.getLogger(MyProgramUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public Main getMainJFrame(){
        return this.threeDMain;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            
            launch(args);
        } catch (Exception ex) {
            Logger.getLogger(MyProgramUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public void setPage(boolean page1,boolean page2,boolean page3){
        this.page1BooleanProperty.set(page1);
        this.page2BooleanProperty.set(page2);
        this.page3BooleanProperty.set(page3);
    }
    public void makeUpConstruction(final Stage primaryStage){
        Group root=new Group();
        //这是边
        Rectangle border = RectangleBuilder.create() 
                .arcWidth(20) 
                .arcHeight(20) 
                .fill(Color.WHITE) 
                .x(10) 
                .y(10) 
                .width(1004)
                .height(688)
                .strokeWidth(2) 
                .stroke(Color.DARKBLUE) 
                .build(); 
        root.getChildren().add(border); 
        border.widthProperty().bind(primaryStage.widthProperty().subtract(20));
        border.heightProperty().bind(primaryStage.heightProperty().subtract(20));
        Rectangle border1 = RectangleBuilder.create() 
                .arcWidth(20) 
                .arcHeight(20) 
                .fill(Color.rgb(38, 188, 213)) 
                .x(15) 
                .y(15) 
                .width(994)
                .height(678)
                .strokeWidth(2) 
                .stroke(Color.rgb(255, 255, 255)) 
                .build(); 
        root.getChildren().add(border1); 
        border1.widthProperty().bind(primaryStage.widthProperty().subtract(30));
        border1.heightProperty().bind(primaryStage.heightProperty().subtract(30));
        
        Header header=new Header(primaryStage,this.threeDMain,controller);
        root.getChildren().add(header);
        
        Rectangle center= RectangleBuilder.create() 
                .fill(Color.rgb(225, 233, 220)) 
                .x(15) 
                .y(95) 
                .width(994)
                .height(571)
                .strokeWidth(0) 
                .stroke(Color.rgb(219, 207, 202)) 
                .build(); 
        root.getChildren().add(center); 
        center.widthProperty().bind(primaryStage.widthProperty().subtract(30));
        center.heightProperty().bind(primaryStage.heightProperty().subtract(137));

        
        
        
        dropShadow.setRadius(5.0);
        dropShadow.setOffsetX(-3.0);
        dropShadow.setOffsetY(3.0);
        dropShadow.setColor(Color.color(0.4, 0.5, 0.5)); 
        //左边栏
        Line line=LineBuilder.create()
                .strokeWidth(2)
                .effect(dropShadow)
                .startX(140)
                .startY(95)
                .endX(140)
                .endY(666)
                .fill(Color.rgb(0, 137, 124))
                .stroke(Color.rgb(0, 137, 124))
                .build();
        root.getChildren().add(line);
        line.startXProperty().bind(primaryStage.widthProperty().divide(7));
        line.endXProperty().bind(primaryStage.widthProperty().divide(7));
        line.endYProperty().bind(primaryStage.heightProperty().subtract(42));
        BoxBlur boxBlur = new BoxBlur();
        boxBlur.setWidth(10);
        boxBlur.setHeight(3);
        boxBlur.setIterations(3);

        //按键分割线
        Line butSepLine=LineBuilder.create()
                .strokeWidth(2)
                .startX(15)
                .startY(100)
                .effect(dropShadow)
                .endX(140)
                .endY(100)
                .stroke(Color.rgb(0, 137, 124))
                .build();
        butSepLine.endXProperty().bind(primaryStage.widthProperty().divide(7));
        butSepLine.startYProperty().bind(center.heightProperty().divide(3).add(85));
        butSepLine.endYProperty().bind(center.heightProperty().divide(3).add(85));
        root.getChildren().add(butSepLine);
        Line butSepLine1=LineBuilder.create()
                .strokeWidth(2)
                .startX(15)
                .startY(100)
                .effect(dropShadow)
                .endX(140)
                .endY(100)
                .stroke(Color.rgb(0, 137, 124))
                .build();
        butSepLine1.endXProperty().bind(primaryStage.widthProperty().divide(7));
        butSepLine1.startYProperty().bind(center.heightProperty().divide(3).multiply(2).add(85));
        butSepLine1.endYProperty().bind(center.heightProperty().divide(3).multiply(2).add(85));
        root.getChildren().add(butSepLine1);
        
        LeftButton leftButton=new LeftButton(line,center, primaryStage,this);
        root.getChildren().add(leftButton);
        
        
        Circle_Ani circle_Ani=new Circle_Ani(primaryStage);
        circle_Ani.setScaleX(0.10f);
        circle_Ani.setScaleY(0.10f);
        circle_Ani.setTranslateX(50);
        circle_Ani.setTranslateY(95);
        circle_Ani.translateYProperty().bind(center.heightProperty().divide(3).subtract(70));
        root.getChildren().add(circle_Ani);
        Circle_Ani circle_Ani1=new Circle_Ani(primaryStage);
        circle_Ani1.setScaleX(0.10f);
        circle_Ani1.setScaleY(0.10f);
        circle_Ani1.setTranslateX(50);
        circle_Ani1.setTranslateY(145);
        circle_Ani1.translateYProperty().bind(center.heightProperty().divide(3).multiply(2).subtract(70));
        root.getChildren().add(circle_Ani1);
        Circle_Ani circle_Ani2=new Circle_Ani(primaryStage);
        circle_Ani2.setScaleX(0.10f);
        circle_Ani2.setScaleY(0.10f);
        circle_Ani2.setTranslateX(50);
        circle_Ani2.setTranslateY(395);  
        circle_Ani2.translateYProperty().bind(center.heightProperty().divide(3).multiply(3).subtract(70));
        root.getChildren().add(circle_Ani2);
        
        //不同的page选项
        //第二页
        DrillPage drillPage=new DrillPage(line, center, primaryStage,controller,brain);
        root.getChildren().add(drillPage);
        drillPage.visibleProperty().bind(page2BooleanProperty);
        //第三页
        AnalysisPage analysisPage=new AnalysisPage(line, center, primaryStage,drillPage);
        root.getChildren().add(analysisPage);
        analysisPage.visibleProperty().bind(page3BooleanProperty);
        //第一页
        SettingPage settingPage=new SettingPage(line, center, primaryStage,drillPage.getTree(),controller);
        root.getChildren().add(settingPage);
        settingPage.visibleProperty().bind(page1BooleanProperty);
        
        Scene scene = new Scene(root, 1366, 748,Color.rgb(227, 230, 195));
        primaryStage.setTitle("煤矿注浆三维模拟评价系统");
        primaryStage.centerOnScreen();
        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.getIcons().add(new Image("Image/starter.png"));
        scene.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(event.getClickCount()==2){
//                    primaryStage.setFullScreen(!primaryStage.isFullScreen());
                    primaryStage.setHeight(748);
                    primaryStage.setWidth(1366);
                    primaryStage.centerOnScreen();
                }
            }
        });
        // starting initial anchor point 
        scene.setOnMousePressed(new EventHandler<MouseEvent>() { 
            public void handle(MouseEvent event){ 
                anchorPt = new Point2D(event.getScreenX(), event.getScreenY()); 
            } 
        }); 
         
        // dragging the entire stage 
        scene.setOnMouseDragged(new EventHandler<MouseEvent>() { 
            public void handle(MouseEvent event){ 
                if (anchorPt != null && previousLocation != null) { 
                    primaryStage.setX(previousLocation.getX() + event.getScreenX() - anchorPt.getX()); 
                    primaryStage.setY(previousLocation.getY() + event.getScreenY() - anchorPt.getY());                     
                } 
            } 
        }); 
         
        // set the current location 
        scene.setOnMouseReleased(new EventHandler<MouseEvent>() { 
            public void handle(MouseEvent event){ 
                previousLocation = new Point2D(primaryStage.getX(), primaryStage.getY()); 
            } 
        });
        Text titleText= TextBuilder.create()
                .font(new Font(48))
                .fill(Color.WHITE)
                .stroke(Color.WHITE)
                .text("煤矿注浆三维模拟评价系统")
                .x(240)
                .y(71)
                .build();
        root.getChildren().add(titleText);
    }
}
